package org.winexpress

import java.security.MessageDigest
import sun.misc.BASE64Encoder
import sun.misc.CharacterEncoder

/**
 *
 * @author Swee Zhi
 */
class UniqueKeyGenerator {

//    static encode = { str ->
//        MessageDigest md = MessageDigest.getInstance('SHA')
//        md.update(str.getBytes('UTF-8'))
//        return (new BASE64Encoder()).encode(md.digest())
//    }
    def generate() {
        def pool = ['a'..'z','A'..'Z',0..9,'_'].flatten()
        Random rand = new Random(System.currentTimeMillis())

        def passChars = (0..16).collect { pool[rand.nextInt(pool.size())] }
        def key = passChars.join()
        
        println 'Generated Unique Key Is (please do not forget this): ' + key
        
        return key
    }

}


